package com.bumptech.glide.load.engine.bitmap_recycle;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Build.VERSION;
import android.util.Log;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class LruBitmapPool
  implements BitmapPool
{
  private static final Bitmap.Config DEFAULT_CONFIG = Bitmap.Config.ARGB_8888;
  private static final String TAG = "LruBitmapPool";
  private final Set<Bitmap.Config> allowedConfigs;
  private int currentSize;
  private int evictions;
  private int hits;
  private final int initialMaxSize;
  private int maxSize;
  private int misses;
  private int puts;
  private final LruPoolStrategy strategy;
  private final BitmapTracker tracker;

  public LruBitmapPool(int paramInt)
  {
    this(paramInt, getDefaultStrategy(), getDefaultAllowedConfigs());
  }

  LruBitmapPool(int paramInt, LruPoolStrategy paramLruPoolStrategy, Set<Bitmap.Config> paramSet)
  {
    this.initialMaxSize = paramInt;
    this.maxSize = paramInt;
    this.strategy = paramLruPoolStrategy;
    this.allowedConfigs = paramSet;
    this.tracker = new NullBitmapTracker(null);
  }

  public LruBitmapPool(int paramInt, Set<Bitmap.Config> paramSet)
  {
    this(paramInt, getDefaultStrategy(), paramSet);
  }

  private void dump()
  {
    if (Log.isLoggable("LruBitmapPool", 2))
      dumpUnchecked();
  }

  private void dumpUnchecked()
  {
    Log.v("LruBitmapPool", "Hits=" + this.hits + ", misses=" + this.misses + ", puts=" + this.puts + ", evictions=" + this.evictions + ", currentSize=" + this.currentSize + ", maxSize=" + this.maxSize + "\nStrategy=" + this.strategy);
  }

  private void evict()
  {
    trimToSize(this.maxSize);
  }

  private static Set<Bitmap.Config> getDefaultAllowedConfigs()
  {
    HashSet localHashSet = new HashSet();
    localHashSet.addAll(Arrays.asList(Bitmap.Config.values()));
    if (Build.VERSION.SDK_INT >= 19)
      localHashSet.add(null);
    return Collections.unmodifiableSet(localHashSet);
  }

  private static LruPoolStrategy getDefaultStrategy()
  {
    if (Build.VERSION.SDK_INT >= 19)
      return new SizeConfigStrategy();
    return new AttributeStrategy();
  }

  private void trimToSize(int paramInt)
  {
    try
    {
      while (true)
      {
        Bitmap localBitmap;
        if (this.currentSize > paramInt)
        {
          localBitmap = this.strategy.removeLast();
          if (localBitmap == null)
          {
            if (Log.isLoggable("LruBitmapPool", 5))
            {
              Log.w("LruBitmapPool", "Size mismatch, resetting");
              dumpUnchecked();
            }
            this.currentSize = 0;
          }
        }
        else
        {
          return;
        }
        this.tracker.remove(localBitmap);
        this.currentSize -= this.strategy.getSize(localBitmap);
        localBitmap.recycle();
        this.evictions = (1 + this.evictions);
        if (Log.isLoggable("LruBitmapPool", 3))
          Log.d("LruBitmapPool", "Evicting bitmap=" + this.strategy.logBitmap(localBitmap));
        dump();
      }
    }
    finally
    {
    }
  }

  public void clearMemory()
  {
    if (Log.isLoggable("LruBitmapPool", 3))
      Log.d("LruBitmapPool", "clearMemory");
    trimToSize(0);
  }

  public Bitmap get(int paramInt1, int paramInt2, Bitmap.Config paramConfig)
  {
    try
    {
      Bitmap localBitmap = getDirty(paramInt1, paramInt2, paramConfig);
      if (localBitmap != null)
        localBitmap.eraseColor(0);
      return localBitmap;
    }
    finally
    {
    }
  }

  @TargetApi(12)
  public Bitmap getDirty(int paramInt1, int paramInt2, Bitmap.Config paramConfig)
  {
    try
    {
      LruPoolStrategy localLruPoolStrategy = this.strategy;
      Bitmap.Config localConfig;
      Bitmap localBitmap;
      if (paramConfig != null)
      {
        localConfig = paramConfig;
        localBitmap = localLruPoolStrategy.get(paramInt1, paramInt2, localConfig);
        if (localBitmap != null)
          break label150;
        if (Log.isLoggable("LruBitmapPool", 3))
          Log.d("LruBitmapPool", "Missing bitmap=" + this.strategy.logBitmap(paramInt1, paramInt2, paramConfig));
        this.misses = (1 + this.misses);
      }
      while (true)
      {
        if (Log.isLoggable("LruBitmapPool", 2))
          Log.v("LruBitmapPool", "Get bitmap=" + this.strategy.logBitmap(paramInt1, paramInt2, paramConfig));
        dump();
        return localBitmap;
        localConfig = DEFAULT_CONFIG;
        break;
        label150: this.hits = (1 + this.hits);
        this.currentSize -= this.strategy.getSize(localBitmap);
        this.tracker.remove(localBitmap);
        if (Build.VERSION.SDK_INT >= 12)
          localBitmap.setHasAlpha(true);
      }
    }
    finally
    {
    }
  }

  public int getMaxSize()
  {
    return this.maxSize;
  }

  public boolean put(Bitmap paramBitmap)
  {
    if (paramBitmap == null)
      try
      {
        throw new NullPointerException("Bitmap must not be null");
      }
      finally
      {
      }
    if ((!paramBitmap.isMutable()) || (this.strategy.getSize(paramBitmap) > this.maxSize) || (!this.allowedConfigs.contains(paramBitmap.getConfig())))
      if (Log.isLoggable("LruBitmapPool", 2))
        Log.v("LruBitmapPool", "Reject bitmap from pool, bitmap: " + this.strategy.logBitmap(paramBitmap) + ", is mutable: " + paramBitmap.isMutable() + ", is allowed config: " + this.allowedConfigs.contains(paramBitmap.getConfig()));
    for (boolean bool = false; ; bool = true)
    {
      return bool;
      int i = this.strategy.getSize(paramBitmap);
      this.strategy.put(paramBitmap);
      this.tracker.add(paramBitmap);
      this.puts = (1 + this.puts);
      this.currentSize = (i + this.currentSize);
      if (Log.isLoggable("LruBitmapPool", 2))
        Log.v("LruBitmapPool", "Put bitmap in pool=" + this.strategy.logBitmap(paramBitmap));
      dump();
      evict();
    }
  }

  public void setSizeMultiplier(float paramFloat)
  {
    try
    {
      this.maxSize = Math.round(paramFloat * this.initialMaxSize);
      evict();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  @SuppressLint({"InlinedApi"})
  public void trimMemory(int paramInt)
  {
    if (Log.isLoggable("LruBitmapPool", 3))
      Log.d("LruBitmapPool", "trimMemory, level=" + paramInt);
    if (paramInt >= 60)
      clearMemory();
    while (paramInt < 40)
      return;
    trimToSize(this.maxSize / 2);
  }

  private static abstract interface BitmapTracker
  {
    public abstract void add(Bitmap paramBitmap);

    public abstract void remove(Bitmap paramBitmap);
  }

  private static class NullBitmapTracker
    implements LruBitmapPool.BitmapTracker
  {
    public void add(Bitmap paramBitmap)
    {
    }

    public void remove(Bitmap paramBitmap)
    {
    }
  }

  private static class ThrowingBitmapTracker
    implements LruBitmapPool.BitmapTracker
  {
    private final Set<Bitmap> bitmaps = Collections.synchronizedSet(new HashSet());

    public void add(Bitmap paramBitmap)
    {
      if (this.bitmaps.contains(paramBitmap))
        throw new IllegalStateException("Can't add already added bitmap: " + paramBitmap + " [" + paramBitmap.getWidth() + "x" + paramBitmap.getHeight() + "]");
      this.bitmaps.add(paramBitmap);
    }

    public void remove(Bitmap paramBitmap)
    {
      if (!this.bitmaps.contains(paramBitmap))
        throw new IllegalStateException("Cannot remove bitmap not in tracker");
      this.bitmaps.remove(paramBitmap);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool
 * JD-Core Version:    0.6.2
 */